import { Model } from 'mongoose';
import { IMessage } from '../models/types';
import { BaseRepository } from './BaseRepository';

export class MessageRepository extends BaseRepository<IMessage> {
  private messageModel: Model<IMessage>;

  constructor(model: Model<IMessage>) {
    super(model);
    this.messageModel = model;
  }

  async findBySessionId(sessionId: string, limit: number = 100): Promise<IMessage[]> {
    return this.messageModel.find({ sessionId })
      .sort({ createdAt: -1 })
      .limit(limit)
      .lean().exec();
  }
}
